package com.aplink.generic.util.validation;

import android.widget.EditText;

public class Compare extends ValidationBase {
    private String ctrlToValid;
    /**
     * to use this compare Class, we have to assign a input value of this
     * control we then retrieve ctrlToValid by string, generate it to control
     * Object and then call checkValidation( by throw an object)
     */
    private String currentValue;

    public Compare() {
        this.currentValue = "";
        this.ErrorMessage = "";
        this.setCtrlToValid( "" );
    }

    public Compare( String ctrltoValid, String errormessage ) {
        this.setCtrlToValid( ctrltoValid );
        this.ErrorMessage = errormessage;
    }

    public Compare( String currentvalue, String ctrltoValid, String errormessage ) {
        this.currentValue = currentvalue;
        this.setCtrlToValid( ctrltoValid );
        this.ErrorMessage = errormessage;
    }

    @Override
    public boolean checkValidation( Object ctrlCompare ) {

        if ( ctrlCompare instanceof EditText ) {
            final String inputValue = ( (EditText) ctrlCompare ).getText().toString();
            if ( this.currentValue.compareTo( inputValue ) == 0 ) {
                return true;
            } else {
                return false;
            }
        }
        // if you have more control for this Validation Type, please define here

        // end of expansion
        else {
            return false;
        }
    }

    public String getCtrlToValid() {
        return this.ctrlToValid;
    }

    public String getCurrentValue() {
        return this.currentValue;
    }

    public void setCtrlToValid( String ctrlToValid ) {
        this.ctrlToValid = ctrlToValid;
    }

    public void setCurrentValue( String currentvalue ) {
        this.currentValue = currentvalue;
    }
}
